new Vue({
	el: "body",
	data: {
		userid: "",
		ifdl: false,
		userinfo: "",
		Coupon: [],
		money: 0.00,
		username: "",
		phonenum: "",
		integral: 0,
		showadress: false,
		adress: [],
		newadress: ""
	},
	created: function() {
		this.leancloudinit();
	},
	methods: {
		tzdl: function() {
			location.href = "../login/login.html";
		},
		dc: function() {
			AV.User.logOut();
			this.ifdl = false;
		},
		leancloudinit: function() {
			var _this = this;
			var APP_ID = 'c4w6bVvWfh8xxcmkBE1G0gIt-gzGzoHsz';
			var APP_KEY = 'JBikg4Ksk76zcTi5BKYWvTJF';
			AV.init({
				appId: APP_ID,
				appKey: APP_KEY
			});
			if(AV.User.current() == null) {
				this.ifdl = false;
			} else {
				this.ifdl = true;
				var phonenum = AV.User.current().attributes.username;
				var query = new AV.Query('ELM_user');
				query.contains('phonenum', '' + phonenum + '');
				query.find().then(function(data) {
					_this.userid = data[0].id;
					_this.username = data[0].attributes.username;
					_this.phonenum = data[0].attributes.phonenum;
					_this.integral = data[0].attributes.integral;
					_this.userinfo = data[0];
					_this.Coupon = eval(data[0].attributes.Coupon);
					_this.money = data[0].attributes.money;
					_this.adress = eval(data[0].attributes.adress);
				}, function(error) {
					// 异常处理
				});
			}
		},
		tzmoney: function() {
			if(AV.User.current() == null) {
				alert("请登录后查看");
			} else {
				location.href = "../money/money.html";
			}
		},
		tzCoupon: function() {
			if(AV.User.current() == null) {
				alert("请登录后查看");
			} else {
				location.href = "../Coupon/Coupon.html";
			}
		},
		tzintegral: function() {
			if(AV.User.current() == null) {
				alert("请登录后查看");
			} else {
				location.href = "../integral/integral.html";
			}
		},
		tzAdress: function() {
			if(AV.User.current() == null) {
				alert("请登录后查看");
			} else {
				this.showadress = true;
			}
		},
		tzOrder: function() {
			location.href = "../orderlist/orderlist.html";
		},
		tzFind: function() {
			location.href = "../find/find.html";
		},
		addadress: function() {
			if(this.newadress != "") {
				var newadress = this.newadress;
				this.adress.push(newadress);
				var userid = this.userid;
				var adress = this.adress;
				var newarr = [];
				for(var i = 0; i < adress.length; i++) {
					newarr.push("'" + adress[i] + "'");
				}
				var todo = AV.Object.createWithoutData('ELM_user', userid);
				todo.set('adress', '[' + newarr + ']');
				todo.save();
				this.newadress = "";
			} else {
				alert("地址不能为空");
			}

		}

	}
})